package com.foreknow.demo5;

public class MethodDemo6 {
    public static int[] sum(int [] array){
//        int[] array = {15,7,22,14,8,16,10};
        int temp = 0;
        for(int i = 1;i < array.length;i++) { //控制总的比较次数
            //相邻的两个元素比较
            for(int j = 0;j < array.length-i;j++) {
                if(array[j] > array[j+1]) {
                    temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }



        return array;
    }
    public static void main(String[] args) {
        int[] array = {15,7,22,14,8,16,10};
        int[] sum= MethodDemo6.sum(array);
        for(int i = 0;i<array.length;i++) {
            System.out.println(sum[i]);
        }



    }
    }

